package com.topisv.tms.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.Userrole;

public interface UserroleDao extends PagingAndSortingRepository<Userrole, Long> {
	@Modifying
	@Query("select ur from Userrole ur where ur.user.id = ?1")
	List<Userrole> findByUser_id(Long user_id);
	
	@Query("select ur from Userrole ur where ur.user.userType = ?1 and ur.role.rolename in ?2  and ur.user.areagroups like ?3")
	List<Userrole> findByRoleName(String userType,List<String> roleName,String areagroups);
	
	@Query("select ur from Userrole ur where ur.user.userType = ?1 and ur.role.rolename in ?2")
	List<Userrole> findByRoleName(String userType,List<String> roleName);
	
	@Modifying
	@Query("delete from Userrole ur where ur.user.id = ?1")
	void deleteByUser_id(Long user_id);
}
